/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanterre.annuaire.forStruts;

import com.nanterre.annuaire.bd.BDInteraction;
import com.nanterre.annuaire.model.Composante;
import com.nanterre.annuaire.model.Domaine;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author albran
 */
public class ModifierAffichage extends org.apache.struts.action.Action {

    /*
     * forward name="success" path=""
     */
    

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        response.setContentType("text/html;charset=UTF-8");
        String type = request.getParameter("typeAffichage");
        PrintWriter out = response.getWriter();
        BDInteraction bdi = new BDInteraction();
        //si c'est domaine, alors on doit passé à composante
        if("domaine".equals(type)){
            List<Composante> listComposante = bdi.getAllComposantes();
            for(Composante current : listComposante){
                out.println("<li id=\"COMPOSANTE"+current.getId()+"\" class=\"fermer\">");
                out.println("<a href=\"#\" class=\"arbre\" onclick=\"deroulerElement('"+current.getId()+"', '"+current.getType().getLabel()+"', '-1');return false;\">");
                out.println("<span class=\"test\">"); 
                out.println("<img class=\"derouler\" src=\"images/derouler.jpg\" alt=\"dérouler les informations\" />"+current.getLibelleComplet());
                out.println("</span>");
                out.println("</a>");
                out.println("</li>");
            }
        } else{
            List<Domaine> listDomaines = bdi.getAllDomaines();
            for(Domaine current : listDomaines){
                out.println("<li id=\"DOMAINE"+current.getId()+"\" class=\"fermer\">");
                out.println("<a href=\"#\" class=\"arbre\" onclick=\"deroulerElement('"+current.getId()+"', '"+current.getType().getLabel()+"', '-1');return false;\">");
                out.println("<span class=\"test\">"); 
                out.println("<img class=\"derouler\" src=\"images/derouler.jpg\" alt=\"dérouler les informations\" />"+current.getLibelleComplet());
                out.println("</span>");
                out.println("</a>");
                out.println("</li>");
            }
        }
        out.flush();
        return null;
    }
}
